extends Area2D

@export var vehicles: Array[Texture2D]

var _extra_speen: float

@onready var particles: GPUParticles2D = $Particles2D
@onready var sprite: Sprite2D = $Sprite2D


func _ready() -> void:
	var random_texture: Texture2D = vehicles.pick_random()
	sprite.texture = random_texture
	
	_update_extra_speed()


func _process(delta: float) -> void:
	position.x -= delta * (Global.speed + _extra_speen)


func disable_particles() -> void:
	particles.emitting = false


func _update_extra_speed() -> void:
	var min_extra_speed: float = Global.speed * 1.2
	var max_extra_speed: float = Global.speed * 1.5
	
	_extra_speen = randf_range(min_extra_speed, max_extra_speed)
	

func _on_parent_progress_made() -> void:
	_update_extra_speed()
